﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Jabr.Logic.Roster;

namespace Jabr.GUI.Forms
{
    public partial class ChatForm : Form
    {
        private AbstractAccount m_me;
        private DisplayableContact m_partner;

        static private string m_format = "({0}) <{1}> {2}\r\n";

        public ChatForm(AbstractAccount me, DisplayableContact partner)
        {
            InitializeComponent();

            this.Text += " with: " + partner.ContactID;

            this.m_me = me;
            this.m_partner = partner;
        }

        private void CloseBtn_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void OkBtn_Click(object sender, EventArgs e)
        {
            this.ChatTo(this.InputBox.Text);
        }

        public void ChatTo(string msg)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat(ChatForm.m_format, DateTime.Now.ToLongTimeString(), m_me.Username, msg);
            this.DialogBox.Text += sb.ToString();
            this.m_me.ChatTo(m_partner.ContactID, msg);
            this.InputBox.Text = "";
        }

        public void ChatFrom(string msg)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat(ChatForm.m_format, DateTime.Now.ToLongTimeString(), m_partner.ContactName, msg);
            this.DialogBox.Text += sb.ToString();
        }
    }
}
